package com.demo.demo;

import com.demo.demo.multi_properties.MultiPropertiesDemo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @author ayatsuji
 * @date 2021-06-13 22:18
 * @since
 */
@EnableConfigurationProperties({MultiPropertiesDemo.class})  //  Configuration类增加注解@EnableConfigurationProperties就能指定使用@ConfigurationProperties的类作为bean注入到spring中，而无需@Component注解，见MultiPropertiesDemo
@Configuration
public class TestConfig {

    @Autowired
    private List<Show> shows;

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Bean
    public CommandLineRunner showAll() {
        return args -> {
            for (Show show: shows) {
                Class c = show.getClass();
                logger.info("来自: {} start==============", c);
                show.showAll();
                logger.info("来自: {} end================", c);
            }
        };
    }

    public interface Show {
        void showAll();
    }
}
